package com.txh.blog.exceprtion.handle;

import com.txh.blog.consts.ResultEnum;
import com.txh.blog.exceprtion.exceptions.NullAttrException;
import com.txh.blog.util.ResultJsonUtils;
import com.txh.blog.vo.ResultJson;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常捕获类
 */
@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public ResultJson handle(Exception e){
        //如果是空参数抛出空错
        if(e instanceof NullAttrException){
            return ResultJsonUtils.error(ResultEnum.NULL_ATTR);
        }
        return ResultJsonUtils.systemError(e.getMessage());
    }
}
